package com.example;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.ws.rs.core.Response;
import java.io.IOException;

@Controller
@RequestMapping("/com")
public class HomeWork2 {


    @RequestMapping("/example")
    @ResponseBody
    public void test(String name, String num,  MultipartFile file) throws IOException {
        System.out.println("file : " + file);


        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-h2.xml");
        JdbcTemplate bean = context.getBean(JdbcTemplate.class);
        System.out.println("---------------------");
        byte[] fileBytes = file.getBytes();
        String fileName = file.getName();
        System.out.println(fileName+"   "+fileBytes);
        bean.update("insert into product values (?, ?, ?, ?)",name, num, fileName,fileBytes);



    }
}
